/**
 * 自定义hooks，useList返回查，改，删
 */

import { useState } from "react";
import { cloneDeep } from "lodash-es";

function useList<T>(initialState: T[]) {
  const [state, setState] = useState<T[]>(initialState);

  const deleteList = (index: number) => {
    const newList = cloneDeep(state);
    newList.splice(index, 1);
    setState(newList);
  };

  return { state, setState, deleteList };
}

export default useList;
